package edu.hawaii.stack;

import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Test case for the ClearStack abstract data type, which checks to see that a ClearStack
 * containing three elements can be iterated through and that this iteration retrieves the
 * elements in the correct order. 
 *
 * @author Philip M. Johnson
 * @version $Id: TestClearStack.java,v 1.1.1.1 2005/02/02 02:17:52 johnson Exp $
 */
public class TestClearStack extends TestCase {

  // Objects used for testing.
  private Integer one = new Integer(1);
  private Integer two = new Integer(2);
  private Integer three = new Integer(3);

  /**
   * Test the ClearStack iterator.
   */
  public void testNormalOperation() {
    ClearStack stack = new ClearStack();
    stack.push(one);
    stack.push(two);
    stack.push(three);
    ArrayList list = new ArrayList();
    // Go through the elements in the stack and save them in an ArrayList.
    for (Iterator i = stack.getIterator(); i.hasNext(); ) {
      Integer element = (Integer) i.next();
      list.add(element);
    }
    // Now check to see they were there and in the right order.
    assertSame("Testing ClearStack[0]", one, list.get(0));
    assertSame("Testing ClearStack[1]", two, list.get(1));
    assertSame("Testing ClearStack[2]", three, list.get(2));
  }
}
